class MyPage extends BaseList {
    constructor(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl) {
        super(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl);
    }
    SetCriterion(item) {
        item['PurchasedByFilterValue'] = parseInt($("#UserId").val());
        item['StyleNoFilterValue'] = $.trim($('#StyleNoFilterValue').val()) === '' ? null : $.trim($('#StyleNoFilterValue').val());
        item['OverFlagFilterValue'] = $('#OverFlagFilterValue').val();
        return item;
    }
    GetFilter(pageIndex) {
        let item = super.GetFilter(pageIndex);
        // 设置条件
        item = this.SetCriterion(item);
        return JSON.stringify(item);
    }
    FetchAll() {
        $("#StyleNoFilterValue").val("");
        $("#OverFlagFilterValue").val("-1");

        this.$pagination.attr("_msh_page", 1);
        this.FetchForPage(1);
    }
    EmptyTableContent() {
        $("#tabData01 tbody").empty();
        this.$pagination.attr("_msh_page", 1);
    }
    SetTableContent(result) {
        $("#tabData01 tbody").empty();

        let content_01 = '';
        this.numCheckbox = result.length;  // 设置表格中checkbox的数量为表格的行数
        for (let i = 0; i < result.length; i++) {
            let _receiptedFlag = parseInt(result[i].receiptedFlag) === 0 ? "<span class='c2'></span>" : "<span class='c1'></span>";
            let _mrpDate = parseInt(result[i].receiptedFlag) === 0 ? "<span class='n2'>" + result[i].mrpDate + "</span>" : "<span class='n1'>" + result[i].mrpDate + "</span>";
            let _noticeDate = parseInt(result[i].receiptedFlag) === 0 ? "<span class='n2'>" + result[i].noticeDate + "</span>" : "<span class='n1'>" + result[i].noticeDate + "</span>";
            let _poProgress = '<div class="progressbar">' +
                    '   <div class="progressbar-bar" style="width:' + result[i].poProgress + '%;"></div>' +
                    '   <div class="progress-bar-percent">' + result[i].poProgress + '%</div>' +
                    '</div>';
            let _checked = parseInt(result[i].overFlag) === 0 ? "" : "checked";
            let _overFlag = '<div class="switch">' +
                    '    <input id="' + result[i].poNoticeId + '" type="checkbox"' + _checked + ' onclick="_Instance.SetOverFlag($(this));">' +
                    '    <label for="' + result[i].poNoticeId + '"><span>是</span><span>否</span></label>';
            '</div>';
            content_01 += '<tr _mash_id="' + result[i].poNoticeId + '" _mash_mrp_id="' + result[i].mrpId + '" _mash_mrp_type="' + result[i].billType + '">';
            content_01 += '<td style="text-align:center;">' + _receiptedFlag + '</td>';
            content_01 += '<td><span style="cursor:pointer;" onclick="_Instance.ReceipteMrp($(this));">' + formatNullData(result[i].styleNo) + '</span></td>';
            let _billType = "";
            switch (result[i].billType) {
                case 0:
                    _billType = "提前组料单";
                    break;
                case 1:
                    _billType = "定版调达表";
                    break;
                case 2:
                    _billType = "辅资材调达表";
                    break;
                case 3:
                    _billType = "补料单";
                    break;
            }
            content_01 += '<td style="text-align:center;">' + _billType + '</td>';
            content_01 += '<td style="text-align:center;">' + _mrpDate + '</td>';
            content_01 += '<td style="text-align:center;">' + _noticeDate + '</td>';
            content_01 += '<td>' + _poProgress + '</td>';
            content_01 += '<td style="text-align:center;">' + _overFlag + '</td>';
            if (parseInt(result[i].overFlag) !== 1) {
                let date1 = result[i].noticeDate;
                let date2 = getCurrentDate();
                let aDate = date1.split("-");
                let oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);  //转换为yyyy-MM-dd格式
                aDate = date2.split("-");
                let oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);
                let iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24); //把相差的毫       
                content_01 += '<td style="border-right:none;">' + (isNaN(iDays) ? '' : iDays) + '（天）</td>';
            } else {
                content_01 += '<td style="border-right:none;">' + '</td>';
            }
            content_01 += '</tr>';

            $("#tabData01 tbody").append(content_01);
            content_01 = '';
        }
        setOneTableRowColor("tabData01");
    }
    // 设置已阅标记后跳转到相应的物料需求计划表
    ReceipteMrp($self) {
        let _params = {};
        _params['PoNoticeId'] = $self.parent().parent().attr("_mash_id");
        _params['MrpId'] = $self.parent().parent().attr("_mash_mrp_id");
        _params['MrpType'] = $self.parent().parent().attr("_mash_mrp_type");
        _params['PurchasedBy'] = $("#UserId").val();
        // 设置已阅标记
        this.DoAjax(_params, "/purchase/po_notice/setReceiptedFlag.html", (data) => {
            if (data > 0) {
                // 设置当前页
                $.cookie(this.cokiePageIndex, parseInt(this.$pagination.attr("_msh_page")));
                // 保存过滤条件
                this.SaveFilters();
                switch (parseInt($self.parent().parent().attr("_mash_mrp_type"))) {
                    case 0:
                        // 提前组料
                        location.assign(parent.basePath + '/tech/mrp/main/4/' + $self.parent().parent().attr("_mash_mrp_id") + '/edit.html');
                        break;
                    case 1:
                        // 定版调达
                        location.assign(parent.basePath + '/tech/mrp/main_final/4/' + $self.parent().parent().attr("_mash_mrp_id") + '/edit.html');
                        break;
                    case 2:
                        // 辅资材
                        location.assign(parent.basePath + '/tech/mrp/auxiliary/4/' + $self.parent().parent().attr("_mash_mrp_id") + '/edit.html');
                        break;
                    case 3:
                        // 补料单
                        location.assign(parent.basePath + '/tech/mrp/feeding/4/' + $self.parent().parent().attr("_mash_mrp_id") + '/edit.html');
                        break;
                }
            } else {
                ShowErrorMessagePanel('阅读标记设置出现问题。');
            }
        });
    }
    // 设置采购担当自己负责下单的完成状态
    SetOverFlag($self) {
        let _params = {};
        _params['PoNoticeId'] = $self.parent().parent().parent().attr("_mash_id");
        _params['MrpId'] = $self.parent().parent().parent().attr("_mash_mrp_id");
        _params['MrpType'] = $self.parent().parent().parent().attr("_mash_mrp_type");
        _params['PurchasedBy'] = $("#UserId").val();
        _params['OverFlag'] = $self.is(":checked") ? "1" : "0";   // 完成标记
        // 设置已阅标记
        this.DoAjax(_params, "/purchase/po_notice/setOverFlag.html", (data) => {
            if (data > 0) {
                ShowSuccessMessagePanel('下单完成状态设置成功。');
            } else {
                ShowErrorMessagePanel('下单完成状态设置成功出现问题。');
            }
        });
    }
    SaveFilters() {

    }
    RestoreFilters() {

    }
}

var _Instance = null;

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    $("#page-size").val($.cookie("po_notice_list_pagesize") === undefined ? 15 : $.cookie("po_notice_list_pagesize"));
    // 删除已经保存的检索后的数据列表标识数组
    $.cookie("po_notice_list_result", null);

    _Instance = new MyPage(0, null, 0,
            $("#page-size"),
            $("abbr.page_indicator_block,#wrapper__navbar"),
            "po_notice_list_pagesize",
            "po_notice_list_pageindex",
            "po_notice_list_result",
            "/purchase/po_notice/fetchForPage.html",
            "");

    // 设置分页控制 （操作区域）
    $("#wrapper__navbar").swPagination({
        link_string: '/?page={page_number}',
        max_page: null,
        paged: function (page) {
            $("abbr.page_indicator_block,#wrapper__navbar").attr("_msh_page", page);
            _Instance.FetchForPage(page);
        }
    });

    _Instance.OnPageLoad();
}

// 画面大小或者位置移动
function onPageResize() {
}